#include "stdafx.h"
#include "DiabloClone.h"

extern bool g_bExitGame;
LRESULT CALLBACK	WndProc(HWND, UINT, WPARAM, LPARAM);

//
//  FUNCTION: RegisterWindow(HINSTANCE)
//
//  PURPOSE: Registers the window class.
//
//  COMMENTS:
//
//    This function and its usage are only necessary if you want this code
//    to be compatible with Win32 systems prior to the 'RegisterClassEx'
//    function that was added to Windows 95. It is important to call this function
//    so that the application will get 'well formed' small icons associated
//    with it.
//
HWND RegisterWindow(HINSTANCE hInstance)
{	
	WNDCLASSEX wcex;

	wcex.cbSize = sizeof(WNDCLASSEX);

	wcex.style			= CS_HREDRAW | CS_VREDRAW;
	wcex.lpfnWndProc	= WndProc;
	wcex.cbClsExtra		= 0;
	wcex.cbWndExtra		= 0;
	wcex.hInstance		= hInstance;
	wcex.hIcon			= LoadIcon(hInstance, MAKEINTRESOURCE(IDI_DIABLOCLONE));
	wcex.hCursor		= LoadCursor(NULL, IDC_ARROW);
	wcex.hbrBackground	= (HBRUSH)(COLOR_WINDOW+1);
	wcex.lpszMenuName	= NULL;
	wcex.lpszClassName	= TEXT("Diablo Clone Class");
	wcex.hIconSm		= LoadIcon(wcex.hInstance, MAKEINTRESOURCE(IDI_SMALL));

	if( !RegisterClassEx(&wcex) )
		return 0;

	 HWND hWnd;	

	hWnd = CreateWindow(TEXT("Diablo Clone Class"), TEXT("Diablo Clone"), WS_OVERLAPPEDWINDOW,
		CW_USEDEFAULT, 0, 1288, 754, NULL, NULL, hInstance, NULL);

	if( hWnd )
	{
		ShowWindow(hWnd, SW_SHOW);
		UpdateWindow(hWnd);
	}


	return hWnd;
}

void HandleMessages(HWND hWnd)
{
	MSG msg;

	// Main message loop:
	while(PeekMessage(&msg, NULL, NULL, 0, PM_REMOVE))
	{
		if (!TranslateAccelerator(msg.hwnd,NULL, &msg))
		{
			TranslateMessage(&msg);
			DispatchMessage(&msg);
		}
	}

}

void CloseRenderWindow(HWND hWnd)
{
	DestroyWindow(hWnd);
}

//
//  FUNCTION: WndProc(HWND, UINT, WPARAM, LPARAM)
//
//  PURPOSE:  Processes messages for the main window.
//
//  WM_COMMAND	- process the application menu
//  WM_PAINT	- Paint the main window
//  WM_DESTROY	- post a quit message and return
//
//
LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
	int wmId, wmEvent;
	PAINTSTRUCT ps;
	HDC hdc;

	switch (message)
	{
	/*case WM_COMMAND:
		wmId    = LOWORD(wParam);
		wmEvent = HIWORD(wParam);
		break;*/
	case WM_PAINT:
		hdc = BeginPaint(hWnd, &ps);
		// TODO: Add any drawing code here...
		EndPaint(hWnd, &ps);
		break;
	case WM_DESTROY:
		PostQuitMessage(0);
		g_bExitGame = true;
		break;
	default:
		return DefWindowProc(hWnd, message, wParam, lParam);
	}
	return 0;
}